package com.tsystems.train.service;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import com.tsystems.train.dao.StationDAO;
import com.tsystems.train.entity.Station;

/**
 * @author Turybrin Vladislav
 * 
 *         The class contains methods for performing basic operations with
 *         stations.
 */
@Stateless
public class StationServices {

	@EJB
	private StationDAO stationDAO;

	/**
	 * Get all trains from database.
	 * 
	 * @return list of stations
	 */
	public List<Station> viewStations() {
		List<Station> stations = stationDAO.getStationList();
		return stations;

	}

	/**
	 * Add new station if it has not already added
	 * 
	 * @param station
	 * 
	 * @return "New station added" if it so, otherwise - message with error
	 *         information
	 */
	public String addStation(Station station) {
		Station stationFound = stationDAO.getStationByName(station.getName());

		if (stationFound != null) {
			return "This station already exist";
		}

		stationDAO.insert(station);
		return "New station added";

	}

}
